<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="en" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<!--<![endif]-->
<!-- BEGIN HEAD -->
<!-- BEGIN BODY -->
<body class="page-header-fixed">
<!-- BEGIN PAGE CONTENT-->
<div class="site_content">
    <div class="realtime_content content_box no_table_filter">
        <div>
            <form  id="form_id" method="post" class="instruct_box w5c-form demo-form"  method="post"  role="form" w5c-form-validate="vm.validateOptions" novalidate name="validateForm">
                <hr />
                <div style="width: 400px">
                    <div class="form-group form1">
                        <label>设备地址</label>
                        <input type="text" class="form-control" id="chargerId" name="chargerId" placeholder="请输入设备地址">
                        <span id="chargerInner"></span>
                    </div>

                    <div class="form-group form1">

                        <label>用户卡号</label> <input type="text" class="form-control" id="userCard" name="userCard" placeholder="请输入20位的用户卡号">
                    	<span id="userInner"></span>

                    </div>
                    <div class="form-group form1">
                        <label>端口号</label>

                        <input class="form-control" id="portNo" name="portNo" placeholder="只能输为一位的数字">

                        <span id="portNoInner"></span>
                    </div>
                    <div class="form-group form1">
                    <label for="">服务器预约流水号</label>
                    <input class="form-control" type="text" id="bespeakStartSerialNumber" name="bespeakStartSerialNumber" placeholder="请输入流水号"/>
                    <span id="numberInner"></span>
                    </div>
                  
                </div>
                <div class="modal-footer t_l">
                    <button style="margin-bottom:0px" type="reset" class="btn btn-warning" data-dismiss="modal">
                        <i class="fa fa-refresh"></i> 重置
                    </button>
                    <button type="button" class="btn btn-danger">
                        <i class="fa fa-times-circle"></i> 取消预约
                    </button>
               
                </div>
            </form>
        </div>
    </div>
</div>
<!-- END PAGE CONTENT-->
</body>
<script>
var  charger = $('#chargerId');
var  user = $('#userCard');
var  port = $('#portNo');
var  numberN =  $('#bespeakStartSerialNumber');
function verify(){
        $('#chargerId').on('blur',function(){
        var chargerId = $('#chargerId').val();
        if(/^\d{16}$/.test(chargerId)){
            
            $('#chargerInner').html('');
            charger.isError=false;
        }else{
            $('#chargerInner').html('设备地址必须为16位数字').css('color','red'); 
            charger.isError=true;
        }
        
    });
    $('#userCard').on('blur',function(){
        var userCard = $('#userCard').val();
        if(/^\d{20}$/.test(userCard)){
            $('#userInner').html('');
            user.isError=false;
        }else{
            $('#userInner').html('用户卡号必须为20位数字').css('color','red');
            user.isError=true;
        }
    });
    $('#portNo').on('blur',function(){
        var portNo = $('#portNo').val();
        if(!/^\d{1}$/.test(portNo)){
            $('#portNoInner').html('端口号只能为1位数字').css('color','red');
           port.isError=true;
        }else{
            $('#portNoInner').html('');
             port.isError=false;
        }
    });
    $('#bespeakStartSerialNumber').on('blur',function(){
        var number = $('#bespeakStartSerialNumber').val();
        if(!/^\d{18}$/.test(number)){
            $('#numberInner').html('预约流水号只能为18位数字').css('color','red');
            numberN.isError=true;
        }else{
            $('#numberInner').html('');
            numberN.isError=false;
        }
    });
}

    verify();
    $('button.btn-danger').on('click',function(){
        if(numberN.isError==false && port.isError == false && user.isError==false && charger.isError==false){
            $.ajax({
            type:'post',
            url:'/oms/cancelBespeak',
            data:$('#form_id').serialize(),
            dataType: "json",
            async: false,
            success:function(data){
                if(data.code == '200'){
                    bootboxWindow.alert("指令下发成功!", null);
                }else{
                    bootboxWindow.alert("指令下发失败!", null);
                    $('#account').val('');
                    $('#password').val('');
                }
            },
            error:function(){
                bootboxWindow.alert("连接服务器失败",null);             }
        })
        }else{
             $('#chargerInner').html('设备地址必须为16位数字').css('color','red'); 
              $('#userInner').html('用户卡号必须为20位数字').css('color','red');
               $('#numberInner').html('预约流水号只能为18位数字').css('color','red');
               $('#portNoInner').html('端口号只能为1位数字').css('color','red');
        }

    });
</script>
</html>
